home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
363
/
xlisp20
/
xlisp_h
/
xlisp.h
< prev
Wrap
Text File
|
1990-02-03
|
9KB
|
339 lines
/* xlisp - a small subset of lisp */
/* Copyright (c) 1985, by David Michael Betz
All Rights Reserved
Permission is granted for unrestricted non-commercial use */
/* system specific definitions */
#define ATARI
#include <stdio.h>
#include <ctype.h>
#ifndef MEGAMAX
#include <setjmp.h>
#endif
/* NNODES number of nodes to allocate in each request (200) */
/* TDEPTH trace stack depth (100) */
/* FORWARD type of a forward declaration () */
/* LOCAL type of a local function (static) */
/* AFMT printf format for addresses ("%x") */
/* FIXNUM data type for fixed point numbers (long) */
/* ITYPE return type for fixed point conversion routine (long) */
/* ICNV fixed point input conversion routine (atol) */
/* IFMT printf format for fixed point numbers ("%ld") */
/* FLONUM data type for floating point numbers (float) */
/* FTYPE return type for floating point conversion routine (double) */
/* FCNV floating point input conversion routine (atof) */
/* FFMT printf format for floating point numbers ("%f") */
/* for the Computer Innovations compiler */
#ifdef CI
#define NNODES 1000
#define TDEPTH 500
#define ITYPE double atoi()
#define ICNV(n) atoi(n)
#define NIL 0
#endif
/* for the CPM68K compiler */
#ifdef CPM68K
#define NNODES 1000
#define TDEPTH 500
#define LOCAL
#define AFMT "%lx"
#define FLONUM double
#undef NULL
#define NULL 0L
#endif
/* for the Atari 520ST (DRI C Compiler) */
#ifdef ATARI
#define NNODES 1000
#define TDEPTH 500
#define LOCAL
#define AFMT "%lx"
#define FLONUM double
#undef NULL
#define NULL 0L
#define getc(fp) stgetc(fp)
#define putc(ch,fp) stputc(ch,fp)
#endif
/* for the DeSmet compiler */
#ifdef DESMET
#define NNODES 1000
#define TDEPTH 500
#define LOCAL
#define getc(fp) getcx(fp)
#define putc(ch,fp) putcx(ch,fp)
#define EOF -1
#endif
/* for the MegaMax compiler */
#ifdef MEGAMAX
#define NNODES 1000
#define TDEPTH 500
#define TSTKSIZE (4 * TDEPTH)
#define LOCAL
#define AFMT "%lx"
#define getc(fp) macgetc(fp)
#define putc(ch,fp) macputc(ch,fp)
#endif
/* for the VAX-11 C compiler */
#ifdef vms
#define NNODES 2000
#define TDEPTH 1000
#endif
/* for the DECUS C compiler */
#ifdef decus
#define NNODES 200
#define TDEPTH 100
#define FORWARD extern
#endif
/* for unix compilers */
#ifdef unix
#define NNODES 200
#define TDEPTH 100
#endif
/* for the AZTEC C compiler (8086) */
#ifdef AZTEC
#define NNODES 1000
#define TDEPTH 500
#define FLONUM double
#define getc(fp) agetc(fp)
#define putc(ch,fp) aputc(ch,fp)
#define NIL 0
#endif
/* default important definitions */
#ifndef NNODES
#define NNODES 200
#endif
#ifndef TDEPTH
#define TDEPTH 100
#endif
#ifndef FORWARD
#define FORWARD
#endif
#ifndef LOCAL
#define LOCAL static
#endif
#ifndef AFMT
#define AFMT "%x"
#endif
#ifndef FIXNUM
#define FIXNUM long
#endif
#ifndef ITYPE
#define ITYPE long atol()
#endif
#ifndef ICNV
#define ICNV(n) atol(n)
#endif
#ifndef IFMT
#define IFMT "%ld"
#endif
#ifndef FLONUM
#define FLONUM float
#endif
#ifndef FTYPE
#define FTYPE double atof()
#endif
#ifndef FCNV
#define FCNV(n) atof(n)
#endif
#ifndef FFMT
#define FFMT "%f"
#endif
#ifndef TSTKSIZE
#define TSTKSIZE (sizeof(NODE *) * TDEPTH)
#endif
/* useful definitions */
#define TRUE 1
#define FALSE 0
#ifndef NIL
#define NIL (NODE *)0
#endif
/* absolute value macros */
#define abs(n) ((n) < 0 ? -(n) : (n))
#define fabs(n) ((n) < 0.0 ? -(n) : (n))
/* program limits */
#define STRMAX 100 /* maximum length of a string constant */
/* node types */
#define FREE 0
#define SUBR 1
#define FSUBR 2
#define LIST 3
#define SYM 4
#define INT 5
#define STR 6
#define OBJ 7
#define FPTR 8
#define FLOAT 9
/* node flags */
#define MARK 1
#define LEFT 2
/* string types */
#define DYNAMIC 0
#define STATIC 1
/* new node access macros */
#define ntype(x) ((x)->n_type)
#define atom(x) ((x) == NIL || (x)->n_type != LIST)
#define null(x) ((x) == NIL)
#define listp(x) ((x) == NIL || (x)->n_type == LIST)
#define consp(x) ((x) && (x)->n_type == LIST)
#define subrp(x) ((x) && (x)->n_type == SUBR)
#define fsubrp(x) ((x) && (x)->n_type == FSUBR)
#define stringp(x) ((x) && (x)->n_type == STR)
#define symbolp(x) ((x) && (x)->n_type == SYM)
#define filep(x) ((x) && (x)->n_type == FPTR)
#define objectp(x) ((x) && (x)->n_type == OBJ)
#define fixp(x) ((x) && (x)->n_type == INT)
#define floatp(x) ((x) && (x)->n_type == FLOAT)
#define car(x) ((x)->n_car)
#define cdr(x) ((x)->n_cdr)
#define rplaca(x,y) ((x)->n_car = (y))
#define rplacd(x,y) ((x)->n_cdr = (y))
#define getvalue(x) ((x)->n_symvalue)
#define setvalue(x,v) ((x)->n_symvalue = (v))
/* symbol node */
#define n_symplist n_info.n_xsym.xsy_plist
#define n_symvalue n_info.n_xsym.xsy_value
/* subr/fsubr node */
#define n_subr n_info.n_xsubr.xsu_subr
/* list node */
#define n_car n_info.n_xlist.xl_car
#define n_cdr n_info.n_xlist.xl_cdr
#define n_ptr n_info.n_xlist.xl_car
/* integer node */
#define n_int n_info.n_xint.xi_int
/* float node */
#define n_float n_info.n_xfloat.xf_float
/* string node */
#define n_str n_info.n_xstr.xst_str
#define n_strtype n_info.n_xstr.xst_type
/* object node */
#define n_obclass n_info.n_xobj.xo_obclass
#define n_obdata n_info.n_xobj.xo_obdata
/* file pointer node */
#define n_fp n_info.n_xfptr.xf_fp
#define n_savech n_info.n_xfptr.xf_savech
/* node structure */
typedef struct node {
char n_type; /* type of node */
char n_flags; /* flag bits */
union { /* value */
struct xsym { /* symbol node */
struct node *xsy_plist; /* symbol plist - (name . plist) */
struct node *xsy_value; /* the current value */
} n_xsym;
struct xsubr { /* subr/fsubr node */
struct node *(*xsu_subr)(); /* pointer to an internal routine */
} n_xsubr;
struct xlist { /* list node (cons) */
struct node *xl_car; /* the car pointer */
struct node *xl_cdr; /* the cdr pointer */
} n_xlist;
struct xint { /* integer node */
FIXNUM xi_int; /* integer value */
} n_xint;
struct xfloat { /* float node */
FLONUM xf_float; /* float value */
} n_xfloat;
struct xstr { /* string node */
int xst_type; /* string type */
char *xst_str; /* string pointer */
} n_xstr;
struct xobj { /* object node */
struct node *xo_obclass; /* class of object */
struct node *xo_obdata; /* instance data */
} n_xobj;
struct xfptr { /* file pointer node */
FILE *xf_fp; /* the file pointer */
int xf_savech; /* lookahead character for input files */
} n_xfptr;
} n_info;
} NODE;
/* execution context flags */
#define CF_GO 1
#define CF_RETURN 2
#define CF_THROW 4
#define CF_ERROR 8
#define CF_CLEANUP 16
#define CF_CONTINUE 32
/* execution context */
typedef struct context {
int c_flags; /* context type flags */
struct node *c_expr; /* expression (type dependant) */
jmp_buf c_jmpbuf; /* longjmp context */
struct context *c_xlcontext; /* old value of xlcontext */
struct node *c_xlstack; /* old value of xlstack */
struct node *c_xlenv; /* old value of xlenv */
int c_xltrace; /* old value of xltrace */
} CONTEXT;
/* function table entry structure */
struct fdef {
char *f_name; /* function name */
int f_type; /* function type SUBR/FSUBR */
struct node *(*f_fcn)(); /* function code */
};
/* memory segment structure definition */
struct segment {
int sg_size;
struct segment *sg_next;
struct node sg_nodes[1];
};
/* external procedure declarations */
extern struct node *xleval(); /* evaluate an expression */
extern struct node *xlapply(); /* apply a function to arguments */
extern struct node *xlevlist(); /* evaluate a list of arguments */
extern struct node *xlarg(); /* fetch an argument */
extern struct node *xlevarg(); /* fetch and evaluate an argument */
extern struct node *xlmatch(); /* fetch an typed argument */
extern struct node *xlevmatch(); /* fetch and evaluate a typed arg */
extern struct node *xlgetfile(); /* fetch a file/stream argument */
extern struct node *xlsend(); /* send a message to an object */
extern struct node *xlenter(); /* enter a symbol */
extern struct node *xlsenter(); /* enter a symbol with a static pname */
extern struct node *xlmakesym(); /* make an uninterned symbol */
extern struct node *xlsave(); /* generate a stack frame */
extern struct node *xlframe(); /* establish a new environment frame */
extern struct node *xlgetvalue(); /* get value of a symbol (checked) */
extern struct node *xlxgetvalue(); /* get value of a symbol */
extern struct node *xlygetvalue(); /* get value of a symbol (no ivars) */
extern struct node *cvfixnum(); /* convert a fixnum */
extern struct node *cvflonum(); /* convert a flonum */
extern struct node *xlgetprop(); /* get the value of a property */
extern char *xlsymname(); /* get the print name of a symbol */
extern struct node *newnode(); /* allocate a new node */
extern char *stralloc(); /* allocate string space */
extern char *strsave(); /* make a safe copy of a string */
əəəəəəəəəəəəəəəəəəəəə